package com.cy.pj.goods.controller;

import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

@Slf4j
//@ControllerAdvice//此注解描述的类为全局异常处理类，在此类中可以定义多个异常处理方法
//@ResponseBody
@RestControllerAdvice//=@ControllerAdvice+@ResponseBody
public class GlobalExceptionHandler {
//  @ExceptionHandler (RuntimeException.class)
//
//    public String  doHandleRuntimeException(RuntimeException e){
//      log.error(e.getMessage());
//      return e.getMessage();
//  }
    @ExceptionHandler (RuntimeException.class)
    public JsonResult  doHandleRuntimeException(RuntimeException e){
        log.error(e.getMessage());
        return new JsonResult(e);
    }
}
